<?php
/**
 * Object Relational Persistence Mapping Class for table: service_item
 *
 * @package	com.clearhealth
 * @author	ClearHealth Inc.
 */
class ServiceItem extends ORDataObject {

	/**#@+
	 * Fields of table: service_item mapped to class members
	 */
	var $ticket_item_id		= '';
	var $service_room_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'service_item';

	/**
	 * Primary Key
	 */
	var $_key = 'ticket_item_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'ServiceItem';

	/**
	 * Handle instantiation
	 */
	function ServiceItem() {
		parent::ORDataObject();
	}
	
	public function getServiceId($ticketItemId) {
		$sql = "select r.service_id
				from service_item i
					inner join service_room r on i.service_room_id = r.service_room_id
				where i.ticket_item_id = $ticketItemId";
		$res = $this->_execute($sql);
		return $res->fields['service_id'];
	}
	
	public function addItem($ticketItemId, $serviceRoomId) {
		$data = array ('ticket_item_id' => $ticketItemId,
						'service_room_id' => $serviceRoomId);
		$this->populateArray($data);
		$this->persist();
	}
	
	public function delete($ticketItemId) {
		$sql = "delete from service_item where ticket_item_id = $ticketItemId";
		$this->_execute($sql);
	}	
}
?>
